package com.example.demo.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class AsyncService {

    @Async("taskExecutor") // 指定线程池名称
    public void executeTask(int taskId) {
        System.out.println(Thread.currentThread().getName() + " is executing Task-" + taskId);
        try {
            Thread.sleep(1000); // 模拟任务执行时间
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            System.err.println("Task interrupted: " + e.getMessage());
        }
    }
}